﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.ComponentModel;
using System.Data;

namespace EWDTAssignment.App_Code
{
    [DataObject]
    public class LiveChatLogic
    {
        [DataObjectMethod(DataObjectMethodType.Select)]
        public static DataTable Upload(DataTable dt)
        {
            DataTable newDt = new DataTable();
            newDt.Columns.Add("message", typeof(string));
            

            string displayMessage;
            for (int i = 0; i < dt.Rows.Count; i++)
            {
                DataRow dr = newDt.NewRow();
                string message = dt.Rows[i][2].ToString();
                string timing = dt.Rows[i][3].ToString();
                string type = dt.Rows[i][4].ToString();
                string username = dt.Rows[i][5].ToString();
                if (type == "Customer")
                {
                    displayMessage = username + " says: (" + timing + ") ";
                }
                else
                {
                    displayMessage = "Customer Service says: " + timing + ") ";
                }
                DataRow newRow = newDt.NewRow();
                newRow["message"] = displayMessage;
                dr["message"] = message;
                newDt.Rows.Add(newRow);
                newDt.Rows.Add(dr);// Rows.Add(dr["Message"]);
                //newDt.Rows.Add(displayMessage,typeof(string));
                //newDt.Rows[i][0]=displayMessage;
            }
            return newDt;
        }
    }
}